package com.zm.zmgz.configure;

import com.zm.zmgz.interceptorzm.AuthorityInterceptor;
import com.zm.zmgz.interceptorzm.SetThreadNameByUserNameInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 和springmvc的webmvc拦截配置一样
 * @author BIANP
 */
@Configuration
public class WebConfigurer implements WebMvcConfigurer { // 拦截器配置
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(AuthorityInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(setThreadNameByUserNameInterceptor()).addPathPatterns("/**");

    }



    /***
    * @Description: 权限拦截器
    * @Param:
    * @return:
    * @Author: cjw
    * @Date: 2020-04-06 14:22:32
    */
    @Bean
    public AuthorityInterceptor AuthorityInterceptor() {
        return new AuthorityInterceptor();
    }

    /***
    * @Description: 设置线程名为用户名
    * @Param:
    * @return:
    * @Author: cjw
    * @Date: 2020-04-06 14:22:47
    */
    @Bean
    public SetThreadNameByUserNameInterceptor setThreadNameByUserNameInterceptor() {
        return new SetThreadNameByUserNameInterceptor();
    }

}
